package logic

import (
	"2day1zy/model/redisinit"
	"context"
	"math/rand"
	"time"

	"2day1zy/userrpc/internal/svc"
	"2day1zy/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type SendSmsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSendSmsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendSmsLogic {
	return &SendSmsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SendSmsLogic) SendSms(in *userrpc.SendSmsRequest) (*userrpc.SendSmsResponse, error) {
	// todo: add your logic here and delete this line

	code := rand.Intn(9000) + 1000

	//sms, err := pkg.SendSms(in.Tel, strconv.Itoa(code))
	//if err != nil {
	//	return nil, err
	//}
	//if *sms.Body.Code != "OK" {
	//	return nil, fmt.Errorf(*sms.Body.Message)
	//}
	redisinit.Rdb.Set("sendsms"+in.Tel, code, time.Hour*8)

	return &userrpc.SendSmsResponse{}, nil
}
